package cn.gong.base.db;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.SyncStateContract.Constants;
import cn.gong.base.Base;
import cn.gong.store.bean.DBParams;
import cn.gong.utils.LogUtils;

public class BaseDb implements Base {

	protected SQLiteOpenHelper dbOpenHelper;

	protected BaseDb(SQLiteOpenHelper openHelper) {
		this.dbOpenHelper = openHelper;
	}

	// 获得数据库
	protected SQLiteDatabase getDb() {
		return dbOpenHelper.getReadableDatabase();
	}

	// 关闭数据库
	protected void closeDb(SQLiteDatabase db) {
		if (db != null && db.isOpen()) {
			db.close();
		}
	}

	// 关闭游标
	protected void closeCursor(Cursor cursor) {
		if (cursor != null && !cursor.isClosed()) {
			cursor.close();
		}
	}

	// 关闭数据库和游标
	protected void closeDbAndCursor(SQLiteDatabase db, Cursor cursor) {
		closeDb(db);
		closeCursor(cursor);
	}

	// insert相关
	
	// update 相关
	

	@Override
	public void log(String msg) {
		LogUtils.log(msg, getClass());
	}

	@Override
	public void log(Object msg) {
		log(String.valueOf(msg));
	}

	@Override
	public void isNull(String name, Object obj) {
		log(name + "==null:" + (obj == null));
	}

	@Override
	public void exception(Exception e) {
		LogUtils.exception(e);
	}

}
